package edu.chinasoft.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.io.PrintWriter;
import javax.servlet.annotation.WebServlet;
import org.apache.log4j.Logger;

import edu.chinasoft.pojo.User;
import edu.chinasoft.service.UserService;
import edu.chinasoft.service.UserServiceImp;

/**
 * 
 * @author cjogng
 * @date 2020年1月17日:上午11:55:44
 * @version V1.0
 * @Description: 生成更新用户页面
*/
@WebServlet(name="myUpdateUserPageForServlet",value="/servlet/updateuserpageforservlet")
public class  UpdateUserPageForServlet  extends HttpServlet {
	private static Logger logger = Logger.getLogger( UpdateUserPageForServlet .class);
	private UserService userService = new UserServiceImp();
	/**
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		logger.debug(" UpdateUserPageForServlet >doGet start.......");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		
		//获取所要更新用户的id
		String idString = request.getParameter("id");
		int id = Integer.parseInt(idString);
		//封装到user对象里，调用服务器层方法获取用户的其他信息
		User user = new User();
		user.setId(id);
		User result = userService.findUserInfo(user);
		//把获取到数据保存到域里
		HttpSession session=request.getSession();
		session.setAttribute("updateuser", result);
		//跳转到更新用户页面
		response.sendRedirect(""+request.getContextPath()+"/updateuser.jsp");
		logger.debug(" UpdateUserPageForServlet >doGet end.......");
	}
	
	/**
	 * 
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		logger.debug(" UpdateUserPageForServlet >doPost start.......");
		this.doGet(request, response);
		
		logger.debug(" UpdateUserPageForServlet >doPost end.......");
	}
	
}